package com.cz.mes.view;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;

import java.io.File;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UpdateVirtualColumn {
    public static void main(String[] args) {
        String dbGroup = "uat3";
        File viewFile = new File("C:\\Users\\root\\Desktop\\view.txt");
        List<String> lines = FileUtil.readLines(viewFile, "utf-8");
        for (String line : lines) {
            String column = line.split(",")[0];
            String tableName = column.split("\\.")[0];
            String columnName = column.split("\\.")[1];
            columnName = StrUtil.subBefore(columnName, " ", false);

            String sql = " update mes_vw_column set db_column_name =:dbColumnName where db_column_name =:columnName and db_table_name =:tableName";
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("dbColumnName", tableName + "." + columnName);
            paramMap.put("columnName", columnName);
            paramMap.put("tableName", "production_requisition_task");
            try {
                int result = Db.use(dbGroup).execute(sql, paramMap);
                System.out.println("更新多少条数据" + result);
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }

    }
}
